from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

path = Service('./chromedriver')
driver = webdriver.Chrome(service=path)
# 打开必应首页
driver.get('https://cn.bing.com/')
# 通过id定位元素
a1 = driver.find_element(By.ID, 'video')
# 通过class属性值的部分进行定位（class="scope try_exp"）
a2 = driver.find_element(By.CLASS_NAME, 'try_exp')
# 通过xpath绝对路径进行定位
a3 = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/header/div[1]/nav/ul/li[2]')
# 通过xpath相对路径进行定位
a4 = driver.find_element(By.XPATH, '//*[@id="video"]')
# 通过xpath,starts-with进行定位(id="video")
a5 = driver.find_element(By.XPATH, '//*[starts-with(@id,"vide")]')
# 通过xpath,contains进行定位(id="video")
a6 = driver.find_element(By.XPATH, '//*[contains(@id,"ideo")]')

# <li class="scope try_exp" id="video" role="menuitem">


print(a1)
print(a2)
print(a3)
print(a4)
print(a5)
print(a6)

# 关闭浏览器
driver.quit()
